/**
 * store 状态
 */
// import { createStore, combineReducers } from "redux";
import { legacy_createStore as createStore, combineReducers } from "redux";
import { CollapsedReducer, LoadingReducer } from "./reducer";

// // 只有一个redux
// const store= createStore(CollapsedReducer);


// // 当有多个redux时, 合并redux
// const reducer= combineReducers({
//     collapsedReducer: CollapsedReducer,
//     loadingReducer: LoadingReducer
// });
// const store= createStore(reducer);
// export default store;


// redux状态持久化
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';  // 将状态存入localstorage中

const persistConfig= {
    key: 'redux-state',
    storage,
    blacklist: ['loadingReducer'],  // 黑名单，里面放置不想被持久化的reducer
    // whitelist: ['collapsedReducer']   // 白名单，里面放置需要被持久化的reducer。 白名单与黑名单只设置一个即可
}

const reducer= combineReducers({
    collapsedReducer: CollapsedReducer,
    loadingReducer: LoadingReducer
});
const persistedReducer= persistReducer(persistConfig, reducer);  // 把普通的reducer 转为持久化的reducer
const store= createStore(persistedReducer);
const persistor= persistStore(store);  // 把普通的store 转为持久化的store
export {
    store,
    persistor
};



/*
 * store.dispatch()  // 发布
 *
 * store.subscribe() // 订阅
 *
 */
